﻿$(document).ready(function () {
    setInterval("slide($('#J_slide_order'),32,500)", 1000);
    $("#J_slide_order").find("li:even").addClass("even");
    $("#J_order_all").find("li:even").addClass("even");

    var light = $("#J_light");
    var J_form = $("#J_form");
    J_form.submit(function () {
        var url = $(this).attr("action");
        var data = {};
        var input = $(this).find("input");
        if (input.eq(0).val().length < 1 || input.eq(1).val().length < 1) { alert("请填写信息"); return false; }
        for (var i = 0; i < input.length; i++) {            
            data[input.eq(i).attr("name")] = input.eq(i).val();
        }
        light.show();
        light.find(".light-bg").css("height", $(document).height());
        light.find(".light-box").css({ left: ($("#J_form").offset().left + 200), top: $("#J_form").offset().top + 50 });
        light.find(".light-iframe").css("height", $(document).height());
        var html = "提交中...";
        light.find(".light-bd").html(html);
        $.ajax({
            async: true,
            type: "post",
            url: url,
            data: data,
            dataType: "text",
            success: function (msg) {
                var data = eval("(" + msg + ")");
                var status = data["loginStatus"];
                var res = data["awardRes"];
                html = "";
                if (status == "3") {
                    html = "<div class='message attention'><s></s><dl><dt>" + res + "</dt></dl></div><div class='light-btn'><a href='http://adrs.sdo.com/ADRefererSystem/adjump.aspx?SndaADID=sdo-shangcheng-110330-01-01&RedirectUrl=http%3a%2f%2fsj.sdo.com%2fSafeMobile%2fScMobile%2fBindMobileIndex.aspx' target='_blank' class='light-btn-signup'></a></div>";
                } else if (status == "2") {
                    html = "<div class='message success'><s></s><dl><dt>" + res + "</dt></dl></div>";
                } else {
                    html = "<div class='message error'><s></s><dl><dt>" + res + "</dt></dl></div>";
                };
                light.find(".light-bd").html(html);
                return false;
            },
            error: function () {
                light.find(".light-bd").html("抱歉，出错了！请刷新页面后再试。");
                return false;
            }
        });
        return false;
    });
    light.find(".light-close").click(function () {
        light.hide();
    });
});

//轮播
function slide(element, step, time) {
    var slide_list = element.find(".slide-list");
    var slide_triggers = element.find(".slide-triggers");
    var count = slide_list.children().length;
    if ((count < 2) || (slide_list.height() < element.height() + step)) { return; }
    var slide_list_first = slide_list.children().eq(0);
    var eq = parseInt(element.attr("data-eq"));
    if (isNaN(eq)) { eq = -1; element.attr("data-eq", "0"); };
    eq += 1;
    if (eq > count - 1) {
        eq = 0;
        slide_list.animate({ top: -count * step }, time, function () {
            slide_list.animate({ top: 0 }, 0);
            slide_list.children().removeAttr("style");
        });
    } else {
        slide_list.animate({ top: -eq * step }, time);
    }
    if (slide_list.height() - count * step < element.height()) {
        for (var i = 0; i < eq - 1; i++) {
            slide_list.children().eq(i).css({ "position": "relative", "top": (count * step) + "px" });
        };
    };
    element.attr("data-eq", eq);
    slide_triggers.children().removeClass("slide-current").eq(eq).addClass("slide-current");
};